package com.gxa.p2p.controller;
import com.gxa.p2p.common.JsonResult;
import com.gxa.p2p.pojo.Article;
import com.gxa.p2p.pojo.Feedback;
import com.gxa.p2p.pojo.Management;
import com.gxa.p2p.service.ManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 邓邦武
 * @author HS
 */
@CrossOrigin
@RestController
@RequestMapping("/management")

@Api(value = "轮播操作接口")
public class ManagementController {

    @Autowired
    private ManagementService service=null;

    /**
     * 邓邦武
     */
    @PostMapping("/findManagementById")
    @ApiOperation(value = "轮播的编号查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "编号",required = true)
    })
    public Map findManagementById(@RequestParam Long id){

        Management management = service.findManagementById(id);

        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("成功");
        jsonResult.setData(management);
        return jsonResult.getDataMap();
    }

    @PostMapping("/findManagementByPage")
    @ApiOperation(value = "轮播的分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name="title",value = "标题",required = false),
            @ApiImplicitParam(name="roaddress",value = "轮播位置",required = false),
            @ApiImplicitParam(name="area",value = "区域",required = false),
            @ApiImplicitParam(name="state",value = "状态",required = false),
            @ApiImplicitParam(name="page",value = "页码",required = true),
            @ApiImplicitParam(name="size",value = "每页记录数",required = true)

    })

    public Map findManagementByPage(@RequestBody Map map){

        Map<Integer, List<Management>> resultMap = service.findManagementByPage(map);
        Integer count=0;
        Set<Integer> set = resultMap.keySet();
        for (Integer integer : set) {
            count=integer;
        }
        List<Management> list = resultMap.get(count);
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("成功");
        jsonResult.setData(list);
        jsonResult.getDataMap().put("count",count);
        return jsonResult.getDataMap();
    }

    /**
     * 邓邦武
     * @param management
     * @return
     */
    @PostMapping("/addManagement")
    @ApiOperation(value = "增加轮播")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "management",value = "轮播信息",required = true,paramType = "body")
    })
    public Map addManagement(@RequestBody Management management){

        service.addManagement(management);
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("成功");

        return jsonResult.getDataMap();
    }

    /**
     * 邓邦武
     * @param id
     * @return
     */
    @PostMapping("/deleteManagement")
    @ApiOperation(value = "删除轮播")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "轮播id",required = true)
    })
    public Map deleteManagement(@RequestParam("id") Long id){

        service.deleteManagement(id);
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("成功");
        return jsonResult.getDataMap();
    }

    /**
     * 邓邦武
     * @param management
     * @return
     */
    @PostMapping("/updateManagement")
    @ApiOperation(value = "修改轮播")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "management",value = "轮播信息",required = true,paramType = "body")
    })
    public Map updateManagement(@RequestBody Management management){


        service.updateManagement(management);
        JsonResult jsonResult=new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("成功");
        Set<String> stringSet=new HashSet<>();
        return jsonResult.getDataMap();


    }





}
